﻿using Sustainalytics.ClientDW.Entities;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Sustainalytics.GCCS.Service
{
    public class GCOverallCompanySummaryExtendedDto : GCOverallCompanySummaryDto
    {
        public List<GCPrincipleTemplateDto> NonCompliantPrinciples { get; set; }
        public DateTime? NonCompliantSince { get; set; }
        public string NonCompliantSinceQuarter
        {
            get
            {
                var quarter = (this.NonCompliantSince == null || this.NonCompliantSince == DateTime.MinValue) ? null : GCCSUtility.GetDefaultFormattedGccsQuarter(this.NonCompliantSince.Value);
                return quarter;
            }
        }
        public List<GCPrincipleTemplateDto> WatchListPrinciples { get; set; }
        public DateTime? WatchListSince { get; set; }
        public string WatchListSinceQuarter
        {
            get
            {
                var quarter = (this.WatchListSince == null || this.WatchListSince == DateTime.MinValue) ? null : GCCSUtility.GetDefaultFormattedGccsQuarter(this.WatchListSince.Value);
                return quarter;
            }
        }


        public virtual GCOverallCompanySummaryExtendedDto LoadFrom(GCOverallCompanySummaryExtended data)
        {
            base.LoadFrom(data);

            this.NonCompliantSince = data.NonCompliantSince;
            this.WatchListSince = data.WatchListSince;

            this.NonCompliantPrinciples = data.NonCompliantPrinciples == null ? null : data.NonCompliantPrinciples.Select(el =>
                {
                    GCPrincipleTemplateDto dto = new GCPrincipleTemplateDto();
                    dto.LoadFrom(el);
                    return dto;
                }).ToList();

            this.WatchListPrinciples = data.WatchListPrinciples == null ? null : data.WatchListPrinciples.Select(el =>
                {
                    GCPrincipleTemplateDto dto = new GCPrincipleTemplateDto();
                    dto.LoadFrom(el);
                    return dto;
                }).ToList();

            return this;
        }
    }
}
